/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package putime.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class DBModel {

    protected Connection conn;
    protected PreparedStatement prst;
    public ResultSet rs;

    public DBModel() {
    }

    public void openConnect() {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            try {
                conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=newspapersys_db","sa","123");
            } catch (SQLException ex) {
                Logger.getLogger(DBModel.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DBModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void closeConnect() {

        try {
            if (rs != null) {
                rs.close();
            }
            if (prst != null) {
                prst.close();
            }
            if (conn != null) {
                conn.close();
            }

        } catch (SQLException ex) {
            Logger.getLogger(DBModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
